﻿using System;
using System.Windows;
using System.Windows.Data;

namespace TestBat.Views.Converters
{
    public class PointsMaximumPointsPercentageConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue || values[2] == DependencyProperty.UnsetValue)
                return "N.A.";

            float points = (float)values[0];
            uint maximumPoints = (uint)values[1];

            float percentage;
            try
            {
                percentage = (float)values[2];
            }
            catch
            {
                percentage = (int)values[2];
            }

            string strP = (maximumPoints == 1) ? "point" : "points";
            return String.Format("{0:0.00}", points) + " of " + maximumPoints + " " + strP + " (" + String.Format("{0:0.00}", percentage) + " %)";
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
